/*
 *  debug.h
 *
 *  Copyright (C) 2011  Jason<linux8192@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _DEBUG_H_
#define _DEBUG_H_


#define LOG_LEVEL			3

#if (LOG_LEVEL == 0)
  #define LOGV_ENABLE			1
  #define LOGD_ENABLE			1
  #define LOGW_ENABLE			1
  #define LOGE_ENABLE			1
  #define LOG_TRACE_ENABLE		1
  #define LOG_ENTER_ENABLE		1
  #define LOG_LEAVE_ENABLE		1
#endif

#if (LOG_LEVEL == 1)
  #define LOGV_ENABLE			1
  #define LOGD_ENABLE			1
  #define LOGW_ENABLE			1
  #define LOGE_ENABLE			1
//#define LOG_TRACE_ENABLE		1
//#define LOG_ENTER_ENABLE		1
//#define LOG_LEAVE_ENABLE		1
#endif

#if (LOG_LEVEL == 2)
//#define LOGV_ENABLE			1
  #define LOGD_ENABLE			1
  #define LOGW_ENABLE			1
  #define LOGE_ENABLE			1
//#define LOG_TRACE_ENABLE		1
//#define LOG_ENTER_ENABLE		1
//#define LOG_LEAVE_ENABLE		1
#endif

#if (LOG_LEVEL == 3)
//#define LOGV_ENABLE			1
//#define LOGD_ENABLE			1
  #define LOGW_ENABLE			1
  #define LOGE_ENABLE			1
//#define LOG_TRACE_ENABLE		1
//#define LOG_ENTER_ENABLE		1
//#define LOG_LEAVE_ENABLE		1
#endif

#if (LOG_LEVEL == 4)
//#define LOGV_ENABLE			1
//#define LOGD_ENABLE			1
//#define LOGW_ENABLE			1
  #define LOGE_ENABLE			1
//#define LOG_TRACE_ENABLE		1
//#define LOG_ENTER_ENABLE		1
//#define LOG_LEAVE_ENABLE		1
#endif

#if (LOG_LEVEL == 5)
//#define LOGV_ENABLE			1
//#define LOGD_ENABLE			1
//#define LOGW_ENABLE			1
//#define LOGE_ENABLE			1
//#define LOG_TRACE_ENABLE		1
//#define LOG_ENTER_ENABLE		1
//#define LOG_LEAVE_ENABLE		1
#endif

#ifdef LOGV_ENABLE
  #define LOGV(x...)		printf(x)
#else
  #define LOGV(x...)		do {} while (0)
#endif

#ifdef LOGD_ENABLE
  #define LOGD(x...)		printf(x)
#else
  #define LOGD(x...)		do {} while (0)
#endif

#ifdef LOGW_ENABLE
  #define LOGW(x...)		printf(x)
#else
  #define LOGW(x...)		do {} while (0)
#endif

#ifdef LOGE_ENABLE
  #define LOGE(x...)		printf(x)
#else
  #define LOGE(x...)		do {} while (0)
#endif

#ifdef LOG_TRACE_ENABLE
  #define LOG_TRACE()		printf("[TRACE] %s: %s: %d\n", __FILE__, __FUNCTION__, __LINE__)
#else
  #define LOG_TRACE()		do {} while (0)
#endif

#ifdef LOG_ENTER_ENABLE
  #define LOG_ENTER()		printf("[ENTER] %s: %s: %d\n", __FILE__, __FUNCTION__, __LINE__)
#else
  #define LOG_ENTER()		do {} while (0)
#endif

#ifdef LOG_LEAVE_ENABLE
  #define LOG_LEAVE()		printf("[LEAVE] %s: %s: %d\n", __FILE__, __FUNCTION__, __LINE__)
#else
  #define LOG_LEAVE()		do {} while (0)
#endif

static inline void dump_n_bytes(char *buf, int n)
{
	int	i;
	printf("dump %d bytes from 0x%08x\n", n, ((unsigned int *)(& buf))[0]);
	for (i = 0; i < n; ++i) {
		printf("%02x ", buf[i]);
		if ((i + 1) % 32 == 0) {
			printf("\n");
		}
	}
	if (i % 32 != 0) {
		printf("\n");
	}
}

#endif /* _DEBUG_H_ */
